package com.haixiaoke.flat.house.controller;

import com.haixiaoke.auth.AuthCheck;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.house.domain.House;
import com.haixiaoke.saas.house.service.IHouseService;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.token.FrontTokenComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author panda
 * @Date 2025/7/10
 **/
@RestController
@RequestMapping("/front/flat/house/house")
public class FlatHouseController extends BaseController {
    @Autowired
    private IHouseService houseService;
    @Autowired
    private FrontTokenComponent frontTokenComponent;

    @GetMapping("/page")
    public TableDataInfo page(House house) {
        startPage();
        List<House> list = houseService.flatSelectHouseList(house);
        return getDataTable(list);
    }

    /**
     * 根据用户id查询房源信息
     * @param house
     * @return
     */
    @GetMapping("/pageByUser")
    public TableDataInfo pageByUser(House house) {
        startPage();
        house.setConUserId(frontTokenComponent.getUserIdNotNull());
        List<House> list = houseService.flatSelectHouseListByUser(house);
        return getDataTable(list);
    }

    @AuthCheck
    @GetMapping("/{houseId}")
    public AjaxResult getInfo(@PathVariable String houseId) {
        return success(houseService.flatSelectHouseByHouseId(houseId));
    }
}
